import MyTable from '@/components/MyTable';
import OrderShenhe from '@/pages/Order/components/OrderShenhe';
import OrderShow from '@/pages/Order/components/OrderShow';
import {
  adminPayment,
  cancelOrder,
  cloudDeliveryPayment,
  findByPageOrderList,
  shipments,
} from '@/services/order';
import { getResult } from '@/services/sys/attribute';
import { ActionType } from '@ant-design/pro-table/es/typing';
import { Button, Input, Popconfirm } from 'antd';
import React from 'react';
import { useParams } from 'react-router';
const columns = [
  {
    title: '编号',
    key: 'id',
    dataIndex: 'id',
    search: false,
  },
  {
    title: '下单人员',
    key: 'userName',
    dataIndex: 'userName',
  },
  {
    title: '手机号',
    key: 'phone',
    dataIndex: 'phone',
  },
  {
    title: '订单号',
    key: 'sn',
    dataIndex: 'sn',
  },
  /*, {
  title: "第三方订单",
  key: "partySn",
  dataIndex: "partySn"
}

, {
  title: "支付方式",
  key: "paymentMethod",
  dataIndex: "paymentMethod",
  valueType: "select",
  valueEnum: await getResult ( 'paymentMethod', 0 )
}

*/
  {
    title: '支付状态',
    key: 'paymentStatus',
    dataIndex: 'paymentStatus',
    valueType: 'select',
    valueEnum: await getResult('paymentStatus', 0),
  },
  {
    title: '支付金额',
    key: 'paymentAmount',
    dataIndex: 'paymentAmount',
    valueType: 'money',
    search: false,
  },
  /*  {
    title: "优惠金额",
    key: "discountAmount",
    dataIndex: "discountAmount",
    valueType: 'money',
    search: false,
  }, {
    title: "支付总额",
    key: "totalAmount",
    dataIndex: "totalAmount",
    valueType: 'money',
    search: false,
  },*/
  {
    title: '产品总数',
    key: 'quantity',
    dataIndex: 'quantity',
    search: false,
  },
  {
    title: '支付时间',
    key: 'paymentDate',
    dataIndex: 'paymentDate',
    valueType: 'dateTime',
    search: false,
  },
  {
    title: '订单时间',
    key: 'createDate',
    dataIndex: 'createDate',
    valueType: 'dateRange',
    hideInTable: true,
    // initialValue: [moment().calendar(), moment().add(10, 'days').calendar()],
  },
  {
    title: '订单时间',
    key: 'createDate',
    dataIndex: 'createDate',
    valueType: 'dateTime',
    search: false,
  },
  {
    title: '操作人员',
    key: 'operatorName',
    dataIndex: 'operatorName',
    search: false,
  },
  {
    title: '操作',
    key: 'option',
    valueType: 'option',
    // @ts-ignore
    render: (
      _: any,
      row: {
        id: number | undefined;
        isPay: number | undefined;
        paymentStatus: number | undefined;
        status: number;
      },
      index: any,
      action: ActionType,
    ) => [
      <OrderShow row={row} id={row.id} />,

      row?.isPay == 0 ? (
        <>
          <OrderShenhe
            onSuccess={(we) => {
              action.reload();
            }}
            row={row}
            id={row.id}
          />
          <Popconfirm
            title={'支付确定吗？'}
            onConfirm={() =>
              adminPayment(row.id).then(() => {
                action.reload();
              })
            }
          >
            <Button icon="￥" type="primary">
              支付
            </Button>
          </Popconfirm>
          <Popconfirm
            title={'云代发支付确定吗？'}
            onConfirm={() =>
              cloudDeliveryPayment(row.id).then(() => {
                action.reload();
              })
            }
          >
            <Button icon="￥" type="primary" danger>
              云代发
            </Button>
          </Popconfirm>
        </>
      ) : (
        ''
      ),
      row?.paymentStatus != 3 && row?.status == 2 ? (
        <>
          {' '}
          <Button
            onClick={() =>
              cancelOrder(row.id).then(() => {
                action.reload();
              })
            }
          >
            取消
          </Button>
          <Popconfirm
            title={
              <Input
                onChange={(e) => {
                  let value = e.target.value;
                  console.log(value);
                  //  setFaHuo ( value )
                  //  console.log ( fahuo )
                }}
              />
            }
            onConfirm={() =>
              shipments(row.id).then((res) => {
                action.reload();
              })
            }
            okText="Yes"
            cancelText="No"
          >
            <Button danger>发货</Button>
          </Popconfirm>
        </>
      ) : (
        ''
      ),
    ],
  },
];
export const Cloud: React.FC = () => {
  const params = useParams();
  //userstatus
  return (
    <MyTable
      params={{ type: 1 }}
      search={true}
      request={findByPageOrderList}
      columns={columns}
    />
  );
};
export default Cloud;
